<!--用户详情 -->
<template>
  <div class="detail-index-content">
    <Modal
      v-model="modalValue"
      title="企业用户信息"
      footer-hide
      width="920"
      @on-cancel="cancel"
    >
      <div class="user-main">
        <Row :gutter="30">
          <Col span="24">
            <div class="head-img">
              <img :src="icon1" />
            </div>
            <div class="real-name">用户姓名</div>
          </Col>
          <Col span="8" v-for="item in userList" :key="item.id">
            <div class="user-info-main">
              <div class="info-left">
                <img :src="item.icon" />
              </div>
              <div class="info-right">
                <h4>{{ item.title }}</h4>
                <p>{{ item.num }}</p>
              </div>
            </div>
          </Col>
          <Col span="12">
            <CardMain fontSize="14" itemName="手机号码">15625855</CardMain>
            <CardMain fontSize="14" itemName="用户类型">2312</CardMain>
            <CardMain fontSize="14" itemName="组织部门">组织部门</CardMain>
            <CardMain fontSize="14" itemName="状态">状态</CardMain>
          </Col>
          <Col span="12">
            <CardMain fontSize="14" itemName="注册时间">15625855</CardMain>
            <CardMain fontSize="14" itemName="公司名称">2312</CardMain>
            <CardMain fontSize="14" itemName="用户角色">用户角色</CardMain>
          </Col>
          </Row>
      </div>
    </Modal>
  </div>
</template>

<script type="text/javascript">
import {
  addCompany, // 创建公司
  updateCompany, // 修改公司
} from "@/api/system.js";

import icon1 from "@/assets/icon/icon-user-details-01.png";
import icon2 from "@/assets/icon/icon-user-details-02.png";
import icon3 from "@/assets/icon/icon-user-details-03.png";

export default {
  name: "addUpdateCompany",
  components: {},
  props: {
    echoData: {
      type: Object,
      default: () => {},
    },
    isHide: {
      type: Boolean,
      default: false,
    },
    titleName: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      formData: {
        parentId: "",
        companyName: "",
      },
      userList: [
        {
          id: 1,
          title: "发布信息数量",
          icon: icon1,
          num: 158,
        },
        {
          id: 2,
          title: "被企业接收的信息数量",
          icon: icon2,
          num: 158,
        },
        {
          id: 3,
          title: "在已投标阶段的信息数量",
          icon: icon3,
          num: 158,
        },
      ],
      modalValue: false,
      isLoading: false,
    };
  },
  methods: {
    cancel() {
      this.$emit("update:updateIsHide", false);
    },
    async addCompanyAction() {
      try {
        console.log(this.$props.echoData, "this.$echoData");
        this.formData.parentId = this.$props.echoData.id;
        console.log(2);
        this.isLoading = true;
        let data = await addCompany(this.formData);
        this.isLoading = false;
        this.$Message.success("添加成功！");
        this.$emit("actionSuccess");
        this.$emit("update:updateIsHide", false);
      } catch (error) {
        this.isLoading = false;
      }
    },
    async updateCompanyAction() {
      this.isLoading = true;
      try {
        let data = await updateCompany(this.formData);
        this.isLoading = false;
        this.$Message.success("编辑成功！");
        this.$emit("update:updateIsHide", false);
        this.$emit("actionSuccess");
      } catch (error) {
        this.isLoading = false;
      }
    },
    handleSubmit(name) {
      this.$refs[name].validate((valid) => {
        console.log(valid, "name", this.$props.echoData);
        if (valid) {
          if (this.$props.titleName == "编辑") {
            this.formData.parentId = this.$props.echoData.id;
            this.formData.companyName = this.$props.echoData.title;
            return this.updateCompanyAction();
          }
          this.addCompanyAction();
        }
      });
    },
  },
  created() {
    this.formData.parentId = this.$props.echoData.parentId;
    this.formData.ownType = this.$props.echoData.ownType;
    this.modalValue = this.$props.isHide;
  },
};
</script>

<style lang="less" scoped>
.ivu-radio-group {
  width: 100%;
}
.head-img {
  display: flex;
  justify-content: center;
  img {
    width: 80px;
    height: 80px;
  }
}
.real-name{
  text-align: center;
  font-size: 14px;
  margin: 20px 0 30px 0;
}
.user-info-main {
  display: flex;
  .info-left {
    margin-right: 10px;
  }
  .info-right {
    line-height: 1;
    padding-top: 8px;
    h4 {
      font-size: 16px;
      font-weight: normal
    }
    p {
      font-size: 24px;
      margin-top: 10px;
    }
  }
}
.user-main{
  padding:20px
}
</style>
